#include <inttypes.h>
#include "delay.h"

// delay for ms milli-seconds 
void delay_ms(uint16_t ms) 
{
	volatile uint16_t i;

	for(i=ms;i>0;i--)
	{
		delay_us(1000);
		delay_us(1000); // added for 16MHz clock
	}
} 

void delay_us(uint16_t us)
{

// The following gives the correct delay if FCPU=8MHZ	
	asm volatile (
		"lsl r24" "\n\t"	
		"rol r25" "\n\t"		
		"1: sbiw r24,1" "\n\t"
		"brne 1b"
	);
	
}
